package com.odontosis.view.cheque;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import com.odontosis.util.StringUtilsOdontosis;
import com.odontosis.view.OdontosisForm;

public class FormListaCheque extends OdontosisForm {
	
	private String responsavel;
	
	private String numero;
	
	private String banco;
	
	private String codigo;
	
	private String comentario;

	public String getCodigo() {
		return codigo;
	}

	public String getComentario() {
		return comentario;
	}

	public void setCodigo(String id) {
		this.codigo = id;
	}

	public void setComentario(String comentario) {
		this.comentario = comentario;
	}

	public String getResponsavel() {
		return responsavel;
	}

	public String getNumero() {
		return numero;
	}

	public String getBanco() {
		return banco;
	}

	public void setResponsavel(String responsavel) {
		this.responsavel = responsavel;
	}

	public void setNumero(String numero) {
		this.numero = numero;
	}

	public void setBanco(String banco) {
		this.banco = banco;
	}
	
	public boolean getTudoBranco() {
		return StringUtilsOdontosis.isVazia(getBanco()) && StringUtilsOdontosis.isVazia(getResponsavel()) && StringUtilsOdontosis.isVazia(getNumero()); 
	}
	
	@Override
	public ActionErrors validate(ActionMapping mapping,	HttpServletRequest request) {
		ActionErrors errors = new ActionErrors();
		ActionMessages messages = new ActionMessages();
		Collection<String> erros = null;

		if(getTudoBranco()) {
			messages.add("banco", new ActionMessage("Informe ao menos um dos campos para realizar a pesquisa."));
		}
		
		

		if (messages.size() > 0 && getMetodo() != null) {
			errors.add(messages);
			erros = new ArrayList<String>();
			for (Iterator iterator = messages.get(); iterator.hasNext();) {
				ActionMessage string = (ActionMessage) iterator.next();
				erros.add(string.getKey());
			}
			request.setAttribute("mensagens", erros);
			return errors;
		} else {
			request.setAttribute("mensagens", null);
			return super.validate(mapping, request);
		}

	}
	
	

}
